import React, { useState } from 'react'
import pic from 'dic/pic';
import tools from 'columns/tools'
import { Popover } from 'antd'
import './index.styl'
import { IsIE_nine } from 'utils/format'

export default function HasFinish({ item }) {
    const [picObj] = useState(pic.obj);
    function handleClick(type,url,name) {
        if (IsIE_nine() === 9) {
            window.open(url)
        } else {
            if (type === 4 || type === 2) {
                tools.downloadImg(url,name)
            } else {
                window.open(url)
            }
        }
    }

    return (
        <div className="hasFinish_item">
            <div className='imgs'>
                <img
                    src={
                        picObj[item.type] ||
                        picObj[item.fileUrl.split('.')[item.fileUrl.split('.').length - 1]]
                      }
                    alt={''}
                />
            </div>
            {
                item.fileName && item.fileName.length > 10
                ?
                <Popover content={item.fileName} placement="bottom" getPopupContainer={triggerNode => triggerNode.parentNode}>
                    <div className="name">{item.fileName.slice(0,10)+'...'}</div>
                </Popover>
                :
                <div className="name">{ item.fileName }</div>
            }
            <div className="downLoad-text" onClick={() => handleClick(item.fileType,item.fileUrl,item.fileName)}>下载</div>
        </div>
    )
}
